package com.co.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;

import com.co.controller.IndexPageController;
import com.co.utils.Constants;
import com.co.utils.JPage;
import com.co.utils.MakeEnterDoAction;

/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class IndexPage extends JPage {

	// Components
	private JLabel jLabel1;
	private JButton jButton1;
	private JComboBox jComboBoxLang;
	private JTextField jTextField2;

	// Controller
	private IndexPageController indexPageController;

	// Constructor
	public IndexPage() {
		super();
		this.id = Constants.INDEX_PAGE;

		// Inicializo el controlador.
		indexPageController = IndexPageController.getInstance();
		indexPageController.configure(this.getId(), this);

		// Initialize GUI
		initGUI();
	}

	// SINGLETON
	private static IndexPage indexPageInstance;

	public static IndexPage getInstance() {
		if (indexPageInstance == null) {
			indexPageInstance = new IndexPage();
		}
		return indexPageInstance;
	}

	// Initialize GUI.
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setText("Seleccione el idioma:");
				jLabel1.setBounds(320, 56, 98, 35);
			}

			{
				ComboBoxModel jComboBoxLangModel = new DefaultComboBoxModel(
						Constants.LANGUAGES);
				jComboBoxLang = new JComboBox();
				getContentPane().add(jComboBoxLang);
				jComboBoxLang.setModel(jComboBoxLangModel);
				jComboBoxLang.setBounds(469, 63, 105, 28);
				jComboBoxLang.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						indexPageController.setLanguage(jComboBoxLang
								.getSelectedIndex());
					}
				});
			}
			{
				jButton1 = new JButton();
				getContentPane().add(jButton1);
				jButton1.setText("Continuar");
				jButton1.setBounds(742, 63, 91, 28);

				jButton1.addKeyListener(new MakeEnterDoAction()); // convert
																	// Enter to
																	// an
																	// ActionEvent
				jButton1.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {

						indexPageController.setLanguage(jComboBoxLang
								.getSelectedIndex());
						indexPageController.goToLoginPage();
					}
				});
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * This method should return an instance of this class which does NOT
	 * initialize it's GUI elements. This method is ONLY required by Jigloo if
	 * the superclass of this class is abstract or non-public. It is not needed
	 * in any other situation.
	 */
	public static Object getGUIBuilderInstance() {
		return new IndexPage(Boolean.FALSE);
	}

	/**
	 * This constructor is used by the getGUIBuilderInstance method to provide
	 * an instance of this class which has not had it's GUI elements initialized
	 * (ie, initGUI is not called in this constructor).
	 */
	public IndexPage(Boolean initGUI) {
		super();
	}
}
